package com.bjtu.lms.action.book;

import com.bjtu.lms.model.Book;
import com.bjtu.lms.service.BookService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;

/**
 * 
 * @author yilee
 */
public class ModifyBookAction extends ActionSupport {

	private int id;
	private String ISBN;
	private String name;
	private String synopsis; // 简介
	private String publish; // 出版社
	private String publishTime;
	private String author;
	private double price; // 价格
	private BookService bookService;
	private String result;

	public String getISBN() {
		return ISBN;
	}

	public void setISBN(String ISBN) {
		this.ISBN = ISBN;
	}

	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public String getPublish() {
		return publish;
	}

	public void setPublish(String publish) {
		this.publish = publish;
	}

	public String getPublishTime() {
		return publishTime;
	}

	public void setPublishTime(String publishTime) {
		this.publishTime = publishTime;
	}

	public String getSynopsis() {
		return synopsis;
	}

	public void setSynopsis(String synopsis) {
		this.synopsis = synopsis;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public BookService getBookService() {
		return bookService;
	}

	public void setBookService(BookService bookService) {
		this.bookService = bookService;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Override
	public String execute() throws Exception {
		System.out.println("开始修改图书ISBN=" + ISBN);
		Map session = ActionContext.getContext().getSession();
		if (ISBN == null || ISBN.equals("") || name == null || name.equals("")
				|| author.equals("") || author.equals("")) {
			session.put("book", null);
		} else {
			Book b = bookService.modifyBook(id, ISBN, name, synopsis, publish,
					publishTime, author, price);
			if (b != null) {
				session.put("book", b);
			} else {

				session.put("user", null);
			}
		}
		return SUCCESS;
	}

	// 进入修改界面
	public String beginModify() {
		Book b = bookService.findBooksById(id);
		if (b == null) {
			return ERROR;
		} else {
			ActionContext actionContext = ActionContext.getContext();
			Map session = actionContext.getSession();
			session.put("book", b);
			return SUCCESS;
		}
	}
}
